/**
 * Copyright (c) 2017-2017 All Rights Reserved.
 */
package com.zbest.zpay.exchange.biz.action.pay;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zbest.zpay.exchange.dal.dao.FluxInfoDAO;
import com.zbest.zpay.exchange.dal.model.FluxInfoDO;
import com.zbest.zpay.exchange.helper.FluxInfoStatusManager;
import com.zbest.zpay.service.exchange.model.FluxInfoStatus;
import com.zbest.zpay.service.exchange.model.FluxKeyEnum;
import com.zbest.zpay.service.gw.model.InstStatus;
import com.zbest.zpay.shared.process.BaseAction;
import com.zbest.zpay.shared.process.ProcessResult;

/**
 * 
 *
 * @author Administrator
 * @version $Id: HandleGWResultAction.java, v 0.1 2017-4-24 下午11:34:21 Administrator Exp $
 */
@Service("handleNotifyResultAction")
public class HandleNotifyResultAction extends BaseAction {

    @Resource
    private FluxInfoDAO           fluxInfoDAO;

    @Resource
    private FluxInfoStatusManager fluxInfoStatusManager;

    /** 
     * @see com.zbest.zpay.shared.process.BaseAction#perform(com.zbest.zpay.shared.process.ProcessResult)
     */
    @Override
    public void perform(ProcessResult processResponse) {

        String respCode = getValue(FluxKeyEnum.RESP_CODE.getCode());
        String respMessage = getValue(FluxKeyEnum.RESP_MESSAGE.getCode());
        String instRespCode = getValue(FluxKeyEnum.INST_RESP_CODE.getCode());
        String instRespMessage = getValue(FluxKeyEnum.INST_RESP_CODE.getCode());
        String instStatus = getValue(FluxKeyEnum.INST_STATUS.getCode());

        String fluxStatus = FluxInfoStatus.UNKNOWN.getCode();
        if (instStatus.equals(InstStatus.SUCCESS.getCode())) {
            fluxStatus = FluxInfoStatus.SUCCESS.getCode();
        } else if (instStatus.equals(InstStatus.FAIL.getCode())) {
            fluxStatus = FluxInfoStatus.FAIL.getCode();
        }
        setValue(FluxKeyEnum.FLUX_STATUS.getCode(), fluxStatus);

        FluxInfoDO fluxInfoDO = getValue(FluxKeyEnum.FLUX_INFO_DO.getCode());

        fluxInfoStatusManager.statusCheck(FluxInfoStatus.PROCESS.getCode(), fluxStatus);
        fluxInfoDAO.updateResponseAndStatus(fluxInfoDO.getFluxId(), respCode, respMessage,
            instRespCode, instRespMessage, fluxStatus, FluxInfoStatus.PROCESS.getCode());

    }
}
